/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package outils;

import entityprojet.Comptea;
import entityprojet.CompteaJpaController;
import entityprojet.Compteg;
import entityprojet.ComptegJpaController;
import entityprojet.Compter;
import entityprojet.CompterJpaController;
import entityprojet.Comptet;
import entityprojet.ComptetJpaController;
import entityprojet.Journaux;
import entityprojet.JournauxJpaController;
import entityprojet.Naturecg;
import entityprojet.NaturecgJpaController;
import entityprojet.Sectionanal;
import entityprojet.SectionanalJpaController;
import entityprojet.Taxe;
import entityprojet.TaxeJpaController;
import entityprojet.Typect;
import entityprojet.TypectJpaController;
import entityprojet.Typejo;
import entityprojet.TypejoJpaController;
import entityprojet.Typetaxe;
import entityprojet.TypetaxeJpaController;
import entityprojet.exceptions.NonexistentEntityException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import vue.structure.PlanJournal;

/**
 *
 * @author T.Ron
 */
public class Outils {
    
     public static void ouvrirJframe(JFrame fenetre){
         fenetre.setVisible(true);
     }
     
     public static void supprElement(JList jList1){
              if(!jList1.isSelectionEmpty()){
            TaxeJpaController cjc = new TaxeJpaController ();
            try {
                if(JOptionPane.showConfirmDialog(this,
                        "Voulez vous vraiment supprimer "+jList1.getSelectedValue()+" ?",
                        "Fermeture de l'application",
                        JOptionPane.YES_NO_OPTION)==0){
                    cjc.destroy(Integer.parseInt(jList1.getSelectedValue().toString().split("-")[0].trim()));
                }
            } catch (NonexistentEntityException ex) {
                Logger.getLogger(PlanJournal.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
     }
     public static String[] listeNatureCompte(){
        NaturecgJpaController ncg = new NaturecgJpaController();
        List<Naturecg> lncg = ncg.findNaturecgEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getNumnaturecg()+" - "+lncg.get(i).getIntitulenaturecg();
        }
        return tncg;
     }
     
     public static String[] listeTypeJournal(){
        TypejoJpaController ncg = new TypejoJpaController();
        List<Typejo> lncg = ncg.findTypejoEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getIdTypejo()+" - "+lncg.get(i).getLibelletypejo();
        }
        return tncg;
     }
     
     public static String[] listeTaxe(){
        TypetaxeJpaController ncg = new TypetaxeJpaController();
        List<Typetaxe> lncg = ncg.findTypetaxeEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getIdTypetaxe()+" - "+lncg.get(i).getIntituletypetaxe();
        }
        return tncg;
     }
     
     public static String[] listeSA(){
        SectionanalJpaController ncg = new SectionanalJpaController();
        List<Sectionanal> lncg = ncg.findSectionanalEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getIdSa()+" - "+lncg.get(i).getIntitulesa();
        }
        return tncg;
     }
     
     public static String[] listeCT(){
        TypectJpaController ncg = new TypectJpaController();
        List<Typect> lncg = ncg.findTypectEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getNumtypect()+" - "+lncg.get(i).getIntituletypect();
        }
        return tncg;
     }
     
     public static String[] listeCompteComptable(){
        ComptegJpaController ncg = new ComptegJpaController();
        List<Compteg> lncg = ncg.findComptegEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getIdCg()+" - "+lncg.get(i).getLibellecg();
        }
        return tncg;
     }
     
     public static String[] listeCompteReporting(){
        CompterJpaController ncr = new CompterJpaController();
        List<Compter> lncg = ncr.findCompterEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getIdCr()+" - "+lncg.get(i).getIntitulecr();
        }
        return tncg;
     }
     
     public static String[] listeCompteTiers(){
        ComptetJpaController ncr = new ComptetJpaController();
        List<Comptet> lncg = ncr.findComptetEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getIdCt()+" - "+lncg.get(i).getLibellect();
        }
        return tncg;
     }
     
     public static String[] listeCompteAnalytique(){
        CompteaJpaController ncr = new CompteaJpaController();
        List<Comptea> lncg = ncr.findCompteaEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getIdCa()+" - "+lncg.get(i).getIntituleca();
        }
        return tncg;
     }
     
     public static String[] listeJournaux(){
        JournauxJpaController ncr = new JournauxJpaController();
        List<Journaux> lncg = ncr.findJournauxEntities();
        String[] tncg = new String[lncg.size()];
        for(int i=0;i<lncg.size();i++){
            tncg[i]= lncg.get(i).getNumjo()+" - "+lncg.get(i).getIntitulejo();
        }
        return tncg;
     }
}
